package com.mofang.activity.notice;

import com.mofang.R;
import com.mofang.activity.BaseActivity;
import com.mofang.activity.BaseTitleViewActiviey;
import com.mofang.activity.housesource.PolyEffectiveActivity;
import com.mofang.activity.recommend.RecommendProcessActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SystemNoticeActivity extends BaseTitleViewActiviey implements
		OnClickListener, DialogInterface.OnClickListener {

	private LinearLayout system_serviceTel_ly; // 客服电话
	private LinearLayout system_polyEffective_ly; // 聚划算
	private LinearLayout system_recommendProcess_ly; // 推荐流程
	private LinearLayout system_commissionConditions_ly;// 佣金激励条件
	private LinearLayout system_moFangNews_ly;// 魔方快报
	private LinearLayout system_feedback_ly;// 意见反馈
	private LinearLayout system_versionUpdating_ly;// 版本更新
	private LinearLayout system_aboutUs_ly;// 关于我们
	private LinearLayout system_pushSetting_ly;// 推送设置
	private LinearLayout system_clearCache_ly;// 清除缓存
	ProgressDialog clear_pDialog;
	int clear_count = 0;

	private TextView navigation_title;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_main_system);
		super.onCreate(savedInstanceState);

		initView();

	}

	protected void initView() {
		navigation_title = (TextView) findViewById(R.id.navigation_title);
		navigation_title.setText("系统公告");
		system_serviceTel_ly = (LinearLayout) findViewById(R.id.system_serviceTel_ly);
		system_serviceTel_ly.setOnClickListener(this);

		system_polyEffective_ly = (LinearLayout) findViewById(R.id.system_polyEffective_ly);
		system_polyEffective_ly.setOnClickListener(this);

		system_recommendProcess_ly = (LinearLayout) findViewById(R.id.system_recommendProcess_ly);
		system_recommendProcess_ly.setOnClickListener(this);

		system_commissionConditions_ly = (LinearLayout) findViewById(R.id.system_commissionConditions_ly);
		system_commissionConditions_ly.setOnClickListener(this);

		system_moFangNews_ly = (LinearLayout) findViewById(R.id.system_moFangNews_ly);
		system_moFangNews_ly.setOnClickListener(this);

		system_feedback_ly = (LinearLayout) findViewById(R.id.system_feedback_ly);
		system_feedback_ly.setOnClickListener(this);

		system_versionUpdating_ly = (LinearLayout) findViewById(R.id.system_versionUpdating_ly);
		system_versionUpdating_ly.setOnClickListener(this);

		system_aboutUs_ly = (LinearLayout) findViewById(R.id.system_aboutUs_ly);
		system_aboutUs_ly.setOnClickListener(this);

		system_pushSetting_ly = (LinearLayout) findViewById(R.id.system_pushSetting_ly);
		system_pushSetting_ly.setOnClickListener(this);

		system_clearCache_ly = (LinearLayout) findViewById(R.id.system_clearCache_ly);
		system_clearCache_ly.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (v.getId()) {

		case R.id.system_serviceTel_ly:

			break;

		case R.id.system_polyEffective_ly: // 聚划算
			intent = new Intent(getApplicationContext(),
					PolyEffectiveActivity.class);
			startActivity(intent);
			break;

		case R.id.system_recommendProcess_ly: // 推荐流程
			intent = new Intent(getApplicationContext(),
					RecommendProcessActivity.class);
			startActivity(intent);
			break;

		case R.id.system_commissionConditions_ly: // 佣金激励条件

			break;

		case R.id.system_moFangNews_ly: // 魔方快报
			intent = new Intent(getApplicationContext(),
					MoFangNewsActivity.class);
			startActivity(intent);

			break;

		case R.id.system_feedback_ly: // 意见反馈
			intent = new Intent(getApplicationContext(), FeedbackActivity.class);
			startActivity(intent);

			break;

		case R.id.system_versionUpdating_ly: // 版本更新

			break;

		case R.id.system_aboutUs_ly: // 关于我们
			intent = new Intent(getApplicationContext(), AboutActivity.class);
			startActivity(intent);
			break;

		case R.id.system_pushSetting_ly: // 推送设置

			break;

		case R.id.system_clearCache_ly: // 清除缓存

			// CustomDialog.Builder builder = new Builder(this);
			// builder.setTitle("提示");
			// builder.setMessage("确定要清除缓存吗？");
			// builder.setPositiveButton("确定", this);
			// builder.setNegativeButton("取消", this);
			// builder.create().show();
			// break;

		default:
			break;
		}

	}

	@Override
	public void onClick(DialogInterface arg0, int which) {
		// TODO Auto-generated method stub
		switch (which) {
		case DialogInterface.BUTTON_POSITIVE:// "确认"按钮 弹出清理缓存对话框
			arg0.dismiss();
			clear();
			break;
		case DialogInterface.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框
			arg0.dismiss();
			break;
		default:
			break;
		}
	}

	public void clear() {
		LayoutInflater inflater = LayoutInflater
				.from(SystemNoticeActivity.this);
		View view = inflater.inflate(R.layout.dialog, null);
		Dialog alertDialog = new AlertDialog.Builder(this).setView(view)
				.create();
		alertDialog.show();

		// clear_count = 0;
		// clear_pDialog = new ProgressDialog(MainSystemActivity.this);
		// clear_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		// clear_pDialog.setMessage("清理中，请稍后");
		// clear_pDialog.setIndeterminate(false);
		// clear_pDialog.setProgress(100);
		// clear_pDialog.setCancelable(true);
		// clear_pDialog.show();
		//
		// new Thread() {
		// @Override
		// public void run() {
		// try {
		// while (clear_count <= 100) {
		// clear_pDialog.setProgress(clear_count++);
		// Thread.sleep(100);
		// }
		// clear_pDialog.cancel();
		// } catch (Exception e) {
		// clear_pDialog.cancel();
		// }
		// }
		// }.start();
	}
}
